package authoritah.ui.spend;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JPanel;

import authoritah.db.Spend;


public class SpendController {
	private SpendView view;
	private SpendModel model;
	
	public SpendController() {
		model = new SpendModel();
		view = new SpendView(model);
		
		createAndAssignActions();
	}
	
	private void createAndAssignActions() {
		Action saveAction = new AbstractAction("Save") {
			public void actionPerformed(ActionEvent e) {
				Spend spend = new Spend();
				spend.setDate(view.getDate());
				spend.setEvent(model.getEvent());
				spend.setItem(model.getItem());
				spend.setMember(model.getMember());
				spend.setPointsSpent(model.getPointsSpent());
				Spend.createSpend(spend);
				model.getTableModel().updateData(Spend.getAllSpends());
			}
		};
		view.setSaveAction(saveAction);
	}

	public JPanel getDisplayComponent() {
		return view;
	}
}
